<?php

use yii\db\Migration;

class m210222_082817_addon_asset extends Migration
{
    public function up()
    {
        /* 取消外键约束 */
        $this->execute('SET foreign_key_checks = 0');
        
        /* 创建表 */
        $this->createTable('{{%addon_asset}}', [
            'id' => "int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID'",
            'cate_id' => "int(11) NOT NULL COMMENT '类别'",
            'merchant_id' => "int(11) NOT NULL",
            'serial' => "varchar(32) NOT NULL COMMENT '编号'",
            'title' => "varchar(255) NOT NULL COMMENT '名称'",
            'num' => "int(11) NOT NULL COMMENT '数量'",
            'unit' => "varchar(32) NOT NULL COMMENT '单位'",
            'purchase_price' => "decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '单价'",
            'purchase_date' => "date NOT NULL COMMENT '购买日期'",
            'department' => "varchar(32) NULL COMMENT '使用部门'",
            'address' => "varchar(32) NULL COMMENT '使用地点'",
            'person' => "varchar(255) NULL COMMENT '负责人'",
            'picture' => "varchar(255) NULL COMMENT '主图'",
            'covers' => "text NULL",
            'status' => "int(4) NOT NULL DEFAULT '1' COMMENT '状态'",
            'created_at' => "int(10) NOT NULL COMMENT '创建时间'",
            'updated_at' => "int(10) NOT NULL COMMENT '更新时间'",
            'PRIMARY KEY (`id`)'
        ], "ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='资产登记表'");
        
        /* 索引设置 */
        
        
        /* 表数据 */
        
        /* 设置外键约束 */
        $this->execute('SET foreign_key_checks = 1;');
    }

    public function down()
    {
        $this->execute('SET foreign_key_checks = 0');
        /* 删除表 */
        $this->dropTable('{{%addon_asset}}');
        $this->execute('SET foreign_key_checks = 1;');
    }
}

